﻿@{
    ViewBag.Title = "If1";
}

<div id="div1"></div>
<label>
    <input type="checkbox" data-bind="checked: displayMessage" />
    消息</label>
<div data-bind="visible: displayMessage"> visible属性控制隐藏显示</div>
<div data-bind="if: displayMessage">if判断控制隐藏显示</div>

<ul data-bind="foreach: planets">
    <li>Planet: <b data-bind="text: name"></b>
        <div data-bind="if: capital">
            Capital: <b data-bind="text: capital.cityName"></b>
        </div>
    </li>
</ul>


<script>

    var viewmodel = {
        displayMessage: ko.observable(false),
        planets: [
            { name: 'Mercury', capital: null },
            { name: 'Earth', capital: { cityName: 'Barnsley' } }
        ]
    };
    ko.applyBindings(viewmodel);
</script>
